<?php
/**
 * 店铺
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/8
 * Time: 21:52
 */

namespace app\index\controller;


use app\common\controller\HomeBase;
use app\common\model\FavoritesItem as FavoritesItemModel;
use app\common\model\BoolStatus;

class Shop extends HomeBase 
{

    public function index($id)
    {
        if (!$id) {
            abort('404');
        }

        $favoritesItemModel = new FavoritesItemModel();
        $this->pageSize     = 40;
        $list               = $favoritesItemModel
            ->where('status', '=', BoolStatus::OPEN)
            ->order('id', 'DESC')
            ->where('seller_id', '=', $id)
            ->paginate($this->pageSize);
        $page               = $list->render();
        $this->assign('list', $list->getCollection());
        $this->assign('page', $page);

        $itemArr = $list ? $list->getCollection()->toArray() : [];
        $item = array_shift($itemArr);

        $shop = null;
        if ($item) {
            $data = [
                'seller_id' => $item['seller_id'],
                'shop_title' => $item['shop_title'],
                'provcity' => $item['provcity'],
                'nick' => $item['nick'],
            ];

            $shop = (object) $data;
        }

        $this->assign('shop', $shop);
        $name = $list ? $item['shop_title']: '';
        $this->setSEOInfo($name, $name, $name);
        return $this->fetch('shop/index');
    }
}